<!--
 * @Author: hucc
 * @Date: 2021-10-12 14:35:42
 * @LastEditors: hucc
 * @LastEditTime: 2021-10-12 19:03:46
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="app">
        <my-table :data='students'>
            <!-- v-slot: 简写形式# -->
            <template #thead>
               <th>编号</th>
               <th>姓名</th>
               <th>年龄</th>
            </template>
            <template #td="{item}">
                 <td>{{item.id}}</td>
                 <td>{{item.name}}</td>
                 <td>{{item.age}}</td>
            </template>
        </my-table>
        <!-- 教师表格生成 -->
        <my-table :data="teachers">
            <template #thead>
               <th>编号</th>
               <th>姓名</th>
               <th>薪资</th>
               <th>性别</th>
            </template>
            <template #td="{item}">
                <td>{{item.id}}</td>
                <td>{{item.name}}</td>
                <td>{{item.salary}}</td>
                <td>{{item.gender}}</td>
            </template>
        </my-table>
    </div>
    <script>
        let component1 = {
            props: {
                data: {
                    type: Array,
                    required: true,

                }
            },
            data() {
                return {

                }
            },
            template: `
              <div>
                <table>
                    <thead>
                        <tr>
                            <slot name="thead"></slot>
                            </tr>
                        </thead>
                        <tbody>
                            <tr v-for="(item,index) in data" :key="index">
                                 <slot name="td" :item="item"></slot>
                                </tr>
                            </tbody>
                    </table>
                </div>
            `
        }
        let vm = new Vue({
            el: '#app',
            data: {
                students: [{
                    id: 1,
                    name: 'zs',
                    age: 12
                }, {
                    id: 2,
                    name: 'lisi',
                    age: 15
                }, {
                    id: 3,
                    name: 'ww',
                    age: 18
                }, {
                    id: 4,
                    name: 'lr',
                    age: 16
                }, ],
                teachers: [{
                    id: 1,
                    name: '张老师',
                    salary: 5000,
                    gender: 'male'
                }, {
                    id: 2,
                    name: '李老师',
                    salary: 6000,
                    gender: 'female'
                }, {
                    id: 3,
                    name: '王老师',
                    salary: 7000,
                    gender: 'female'
                }, {
                    id: 4,
                    name: '罗老师',
                    salary: 8000,
                    gender: 'male'
                }, ]
            },
            methods: {},
            created() {},
            components: {
                'myTable': component1
            }
        })
    </script>
</body>

</html>